////#preprocess
///**
// * AUTO_COPYRIGHT_SUB_TAG
// */
//package com.rim.samples.device.push.ui;
//
//import net.rim.device.api.ui.Field;
//import net.rim.device.api.ui.FieldChangeListener;
//import net.rim.device.api.ui.MenuItem;
//import net.rim.device.api.ui.component.CheckboxField;
//import net.rim.device.api.ui.component.Dialog;
//import net.rim.device.api.ui.component.EditField;
//import net.rim.device.api.ui.component.RadioButtonField;
//import net.rim.device.api.ui.component.RadioButtonGroup;
//import net.rim.device.api.ui.container.MainScreen;
//import net.rim.device.api.ui.text.TextFilter;
//
//import com.rim.samples.device.push.PushConfig;
//
///**
// * Push configuration screen.
// */
//public class ConfigScreen extends MainScreen implements FieldChangeListener {
//
//    private EditField portField;
//    private EditField appIdField;
//    private EditField bpsUrlField;
//    private EditField piUrlField;
//    private int bpsFieldIndex;
//
//    private CheckboxField appAckField;
//    
//    private RadioButtonGroup typeGroup;
//    private RadioButtonField enterpriseTypeField;
//    private RadioButtonField publicTypeField;
//
//    public ConfigScreen() {
//        setTitle( "Push Configuration" );
//
//        this.portField = new EditField( "Port: ", "" );
//        this.appIdField = new EditField( "App ID: ", "" );
//        this.bpsUrlField = new EditField( "BPS server URL: ", "" );
//        this.piUrlField = new EditField( "Push Initiator application URL: ", "" );
//        this.appAckField = new CheckboxField( "App Acknowledgment", false );
//        
//        this.typeGroup = new RadioButtonGroup();
//        this.enterpriseTypeField = new RadioButtonField( "Use enterprise (BES) network", typeGroup, false );
//        this.publicTypeField = new RadioButtonField( "Use public (BIS) network", typeGroup, true );
//
//        add( portField );
//        add( appIdField );
//        add( bpsUrlField );
//        add( piUrlField );
//        add( appAckField );
//        add( enterpriseTypeField );
//        add( publicTypeField );
//
//        bpsFieldIndex = bpsUrlField.getIndex();
//        portField.setFilter( TextFilter.get( TextFilter.NUMERIC ) );
//        enterpriseTypeField.setChangeListener( this );
//
//        addMenuItem( new ErasePersistentStoreMenuItem() );
//        addMenuItem( new AlterSimCardMenuItem() );
//    }
//
//    //#ifndef HANDHELD_VERSION_42
//    protected void onUiEngineAttached( boolean attached ) {
//        if( attached ) {
//            load();
//        }
//        super.onUiEngineAttached( attached );
//    }
//    //#endif
//
//    //#ifdef HANDHELD_VERSION_42
//    protected void onDisplay() {
//        super.onDisplay();
//        load();
//    }
//    //#endif
//
//    public void load() {
//        portField.setText( String.valueOf( PushConfig.getPort() ) );
//        appIdField.setText( String.valueOf( PushConfig.getAppId() ) );
//        bpsUrlField.setText( String.valueOf( PushConfig.getBpsUrl() ) );
//        piUrlField.setText( String.valueOf( PushConfig.getContentProviderUrl() ) );
//        appAckField.setChecked( PushConfig.isApplicationAcknoledgementSupported() );
//        enterpriseTypeField.setSelected( PushConfig.isEnterprise() );
//        setDirty( false );
//    }
//
//    public void save() {
//        if( !PersistentStorage.isRegistered() ) {
//            PushConfig.setPort( Integer.parseInt( portField.getText() ) );
//            PushConfig.setAppId( appIdField.getText() );
//            PushConfig.setBpsUrl( bpsUrlField.getText() );
//            PushConfig.setContentProviderUrl( piUrlField.getText() );
//            PushConfig.setApplicationAcknoledgment( appAckField.getChecked() );
//            PushConfig.setEnterprise( enterpriseTypeField.isSelected() );
//
//            PushConfig.saveSettings();
//        } else {
//            Dialog.inform( "You will not be able to modify settings until unregistered" );
//        }
//    }
//
//    private static class ErasePersistentStoreMenuItem extends MenuItem {
//
//        public ErasePersistentStoreMenuItem() {
//            super( "Erase Persistent Store", 0, 1 );
//        }
//
//        public void run() {
//            PersistentStorage.erase();
//            Dialog.inform( "Please re-start the application to take the effect" );
//        }
//    }
//
//    private static class AlterSimCardMenuItem extends MenuItem {
//
//        public AlterSimCardMenuItem() {
//            super( "Simulate SIM Swap", 0, 2 );
//        }
//
//        public void run() {
//            byte[] cardInfo = PersistentStorage.getSimCardInfo();
//            if( cardInfo != null && cardInfo.length > 0 ) {
//                cardInfo[ 0 ] = (byte) ( cardInfo[ 0 ] + 1 );
//                PersistentStorage.setSimCardInfo( cardInfo );
//                Dialog.inform( "Please re-boot the device to take the effect" );
//            } else {
//                Dialog.alert( "SIM card is not saved, please register first" );
//            }
//        }
//    }
//
//    public void fieldChanged( Field field, int context ) {
//        if( field == enterpriseTypeField ) {
//            boolean isEnterprise = enterpriseTypeField.isSelected();
//            if( isEnterprise ) {
//                delete( bpsUrlField );
//            } else {
//                insert( bpsUrlField, bpsFieldIndex );
//            }
//        }
//    }
//}
